# coding=utf-8
from django.contrib.auth.hashers import BasePasswordHasher
from django.contrib.auth.hashers import mask_hash
from django.utils.crypto import constant_time_compare
from collections import OrderedDict
from django.utils.translation import ugettext_noop as _


class PlaintextPasswordHasher(BasePasswordHasher):
    algorithm = 'plaintext_password'
    def salt(self):
        """
        Generates a cryptographically secure nonce salt in ASCII
        """
        return 'salt'

    def encode(self, password, salt=None):
        return "%s" % password

    def verify(self, password, encoded):
        encoded_2 = self.encode(password)
        return constant_time_compare(encoded, encoded_2)

    def safe_summary(self, encoded):
        algorithm == self.algorithm
        salt = self.salt
        return OrderedDict([
            (_('algorithm'), algorithm),
            (_('salt'), mask_hash(salt, show=2)),
            (_('hash'), mask_hash(encoded)),
        ])